package org.yoome.jtools.distributelock;

import org.yoome.jtools.utils.BeanUtil;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.AutoProxyRegistrar;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;


public class LockConfigurationRegistrar
        implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
        Class<?> configuration = LockConfiguration.class;
//        AnnotationAttributes attributes
//                = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(EnableDistributeLock.class.getName()));
//        int order = 0;
//        if (Objects.nonNull(attributes)) {
//            order = attributes.getNumber("order").intValue();
//        }

        //AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(configuration).getBeanDefinition();
        //beanDefinition.getPropertyValues().add("aspectOrder", order);
        BeanUtil.register(configuration, registry);
        BeanUtil.register(RedisConfig.class, registry);
        BeanUtil.register(DistributedLock.class, registry);
        BeanUtil.register(AutoProxyRegistrar.class, registry);
    }
}
